package com.situ.mall.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.situ.mall.pojo.Admin;
import com.situ.mall.mapper.AdminMapper;
import com.situ.mall.pojo.query.AdminQuery;
import com.situ.mall.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GXP
 * @since 2025-09-10
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    //依赖注入
    @Autowired
    private AdminMapper adminMapper;

    //分页查找
    @Override
    public IPage<Admin> list(AdminQuery adminQuery) {
        //Map<String, Object> map = ThreadLocalUtil.get();//如果有需要，通过ThreadLocalUtil可以在三层架构（同一线程内的任何位置）用线程获取token(解析后包含用户信息)
        IPage<Admin> page = new Page<>(adminQuery.getPage(),adminQuery.getLimit());//1创建一个分页对象，用于 MyBatis-Plus 的分页查询。getPage()获取当前页，getLimit())获取每页多少行
        return adminMapper.list(page,adminQuery);//// 2. 调用Mapper方法，传入分页对象和查询条件
    }

    @Override
    public Admin selectByName(String name) {
        return adminMapper.selectByName(name);
    }
}
